#ifndef __DB_H
#define __DB_H

#include <stdlib.h>
#include <stdint.h>
#include <sqlite3.h>

typedef struct{
	sqlite3 *db;
	sqlite3_stmt *stmt;
}dbFile;

#define Stmt sqlite3_stmt*
#define cStmt(s) sqlite3_stmt *s = NULL

#define db_errmsg(db)   sqlite3_errmsg(db->db)

#define db_column_count(db)	sqlite3_column_count((db)->stmt)
#define db_column_name(db,c)	sqlite3_column_name((db)->stmt,c);
#define db_column_type(db,c)	sqlite3_column_type((db)->stmt,c);

#define dbExSql(db,sql)	sqlite3_exec((db)->db,sql,NULL,NULL,NULL)

int db_open(const char *name,dbFile *h);
void db_close(dbFile *h);
int dbStart(dbFile *h);
int dbSql(dbFile *h,const char *sql);
int dbStep(dbFile *h);
void dbDone(dbFile *h);
char *dbGetResultString(dbFile *h,int pos);
uint32_t dbGetResultInt(dbFile *h,int pos);
float dbGetResultReal(dbFile *h,int pos);
void dbDoSql(dbFile *h,char *sql,int (*add)(char *, void *));

#endif
